package com.zoke.daycarpool.ui;

import android.content.Intent;
import android.os.Bundle;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.widget.ImageView;

import com.zoke.daycarpool.R;
import com.zoke.daycarpool.base.BaseUi;
import com.zoke.daycarpool.domain.UserInstense;

/**
 * 过渡页
 * 
 * @author Jack
 *
 */
public class Splash extends BaseUi {
	private ImageView mSplashIv;
	private UserInstense mUserManager;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_splash);
		mUserManager = UserInstense.getInstense(getApplicationContext());
		mSplashIv = (ImageView) findViewById(R.id._splash);
		AlphaAnimation anim = new AlphaAnimation(0.4f, 1.0f);
		anim.setDuration(2000);
		anim.setFillAfter(true);
		anim.setAnimationListener(new AnimationListener() {
			@Override
			public void onAnimationStart(Animation animation) {
			}

			@Override
			public void onAnimationRepeat(Animation animation) {
			}

			@Override
			public void onAnimationEnd(Animation animation) {
				checkLogin();

			}
		});// 把动画去掉了
		mSplashIv.startAnimation(anim);

	}

	@Override
	public void onBackPressed() {
		// 不能退出
	}

	/** 检测登陆 **/
	private void checkLogin() {
		if (mUserManager.isLogin()) {
			// 已经登陆
			mUserManager.initUser();
			mIntent = new Intent(this, Main.class);
			startUI(mIntent);
			Splash.this.finish();
			return;
		}
		// 没有登陆
		mIntent = new Intent(this, Login.class);
		startUI(mIntent);
		Splash.this.finish();
	}

}
